import React, { Component } from 'react'
import './Footer.css'
import PubSub from 'pubsub-js';
export default class Footer extends Component {
  allCheckHandle = (e) => {
    const { checked } = e.target;
    this.props.getTodosStatus(checked);
    PubSub.publish('allcheck',checked)
  };
  render() {
    // 直接对数据进行操作
    const { list } = this.props;
    console.log(list);
    const alltotal = list.length;
    const donetotal = list.filter((item) => item.isDone).length;
    // console.log(alltotal);
    // console.log(donetotal);

    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={alltotal === donetotal}
            onChange={this.allCheckHandle}
          />
        </label>
        <span>
          <span>已完成 {donetotal}</span> / 全部 {alltotal}
        </span>
        <button
          className="btn btn-danger"
          onClick={this.props.deleteAllDoneTodos}
        >
          清除已完成任务
        </button>
      </div>
    );
  }
}
